//
//  QZRename.m
//  map
//
//  Created by 000 on 16/10/13.
//  Copyright © 2016年 faner. All rights reserved.
//

#import "QZRename.h"
#import "constant.h"

@interface QZRename ()
- (IBAction)quedingBC:(id)sender;
@property (weak, nonatomic) IBOutlet UITextField *textView;

@end

@implementation QZRename

+ (instancetype)renameViewWithFrame:(CGRect)frame
{
    QZRename *renameView = [[NSBundle mainBundle] loadNibNamed:@"QZRename" owner:nil options:nil].lastObject;
    renameView.frame = frame;
    renameView.backgroundColor = [UIColor whiteColor];
    return renameView;
}
- (void)awakeFromNib
{
    
    UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(hide)];
    [self addGestureRecognizer:tapGesture];
}
- (void)show
{
    //获取主Window
    UIWindow *keyWindow = [UIApplication sharedApplication].keyWindow;
    [keyWindow addSubview:self];
    self.alpha = 0.0f;
    [UIView animateWithDuration:0.3f animations:^{
        self.alpha = 1.0f;
    } completion:^(BOOL finished) {
        //弹出键盘
        [self.textView becomeFirstResponder];
    }];
}
- (void)hide
{
    [UIView animateWithDuration:0.3f animations:^{
        self.alpha = 0.0f;
    } completion:^(BOOL finished) {
        [self removeFromSuperview];
    }];
}
- (IBAction)quedingBC:(id)sender {
    [self hide];
    if ([self.delegate respondsToSelector:@selector(rename:didDeterMineBtnClickWithText:)]) {
        [self.delegate rename:self didDeterMineBtnClickWithText:self.textView.text];
    }

}
@end
